﻿//-----------------------------------------------------------------
//
// @(#)$Id: PayPalInfoDetail.aspx.cs,v 1.0 2013/12/13 17:22:01 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:22:01 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_BasTableAdapters;
using ebay.Dal.K3DataBaseTableAdapters;

public partial class UI_Bas_PayPalInfoDetail : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
    
        T_CreateDocumentsTypeTableAdapter createAdapter = new T_CreateDocumentsTypeTableAdapter();
        ddlOrderTypeId.DataSource = createAdapter.GetData();
        ddlOrderTypeId.DataTextField = "DocumentsTypeId";
        ddlOrderTypeId.DataBind();
        T_t_AccountTableAdapter accountAdapter=new T_t_AccountTableAdapter ();
        ddlCSideNumber.DataSource = accountAdapter.GetData();
        ddlCSideNumber.DataTextField = "FName";
        ddlCSideNumber.DataValueField = "FAccountId";
        ddlCSideNumber.DataBind ();
        ddlDSideNumber.DataSource = accountAdapter.GetData();
        ddlDSideNumber.DataTextField = "FName";
        ddlDSideNumber.DataValueField = "FAccountId";
        ddlDSideNumber.DataBind();
    }

    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        break;
                    case "U":
                        {
                            this.txtColId.Attributes["readonly"] = "readonly";
                            int ColId = int.Parse(Request.QueryString["id"]);
                            T_PPInfoColTableAdapter Adapter = new T_PPInfoColTableAdapter();
                            DataTable dt = Adapter.GetDataById(ColId);
                            if (dt.Rows.Count > 0)
                            {
                                DataRow r = dt.Rows[0];
                                this.txtColId.Value = r["ColId"].ToString();
                                this.txtCategoryName.Value = r["CategoryName"].ToString();
                                this.txtName.Value = r["Name"].ToString();
                                this.txtType.Value = r["Type"].ToString();
                                this.txtStatus.Value = r["Status"].ToString();
                                this.txtBalanceimpact.Value = r["Balanceimpact"].ToString();
                                this.ddlOrderTypeId.Text = r["OrderTypeId"].ToString();
                                this.txtOrderSummary.Value = r["OrderSummary"].ToString();
                                this.chkCanMatch.Checked = r["CanMatch"].ToString() == "Y" ? true : false;
                                this.chkCanInvoice.Checked = r["CanInvoice"].ToString() == "Y" ? true : false;
                                txtPayPalStatus.Value = r["PayPalStatus"].ToString();
                                txtMnote.Value = r["Mnote"].ToString();
                                ddlCSideNumber.Value = r["CSideNumber"].ToString();
                                ddlDSideNumber.Value = r["DSideNumber"].ToString();
                            }
                        }
                        break;
                }
            }
         }
     }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string userId = Session["UserId"].ToString();

        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_PPInfoColTableAdapter Adapter = new T_PPInfoColTableAdapter();
                        int flag = (int)Adapter.IsExists(int.Parse(txtColId.Value));
                         if (flag == 0)
                         {
                             int val = Adapter.Insert(
                                 int.Parse(txtColId.Value),
                                 txtName.Value,
                                 txtType.Value,
                                 txtStatus.Value,
                                 txtBalanceimpact.Value,
                                 txtCategoryName.Value,
                                 ddlOrderTypeId.SelectedValue,
                                 txtPayPalStatus.Value,
                                 txtOrderSummary.Value,
                                 txtMnote.Value,
                                 userId,
                                 DateTime.Now,
                                 "",
                                 new DateTime(1900, 1, 1),
                                 Convert.ToInt32(ddlDSideNumber.Value),
                                 Convert.ToInt32(ddlCSideNumber.Value),
                                 chkCanMatch.Checked ? "Y" : "N",
                                 chkCanInvoice.Checked ? "Y" : "N"
                                 );
                             if (val > 0)
                             {
                                 Response.Write("<script>alert('添加成功!');window.location.href='PayPalInfo.aspx'</script>");
                             }
                         }
                         else
                         {
                             Response.Write("<script>alert('编号重复!...');</script>");
                         }
                    }
                    break;
                case "U":
                    {
                        T_PPInfoColTableAdapter Adapter = new T_PPInfoColTableAdapter();
                        int val = Adapter.Update(
                            txtName.Value,
                            txtType.Value,
                            txtStatus.Value,
                            txtBalanceimpact.Value,
                            txtCategoryName.Value,
                            ddlOrderTypeId.SelectedValue,
                            txtPayPalStatus.Value,
                            txtOrderSummary.Value,
                            txtMnote.Value,
                            userId,
                            DateTime.Now,
                            "",
                            new DateTime(1900, 1, 1),
                            Convert.ToInt32(ddlDSideNumber.Value),
                            Convert.ToInt32(ddlCSideNumber.Value),
                            chkCanMatch.Checked ? "Y" : "N",
                            chkCanInvoice.Checked ? "Y" : "N",
                            Convert.ToInt32(txtColId.Value)
                            );
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='PayPalInfo.aspx'</script>");
                        }
                    }
                    break;
            }
        }
    }   
}
